import 'package:flutter/material.dart';
import 'dart:developer' as developer;
import 'package:flutter/cupertino.dart';

///
///   按钮组件
///   TextButton  (基本无边框的 文本 和图标按钮)
///   https://api.flutter-io.cn/flutter/material/TextButton-class.html
///
///  OutlinedButton 带轮廓的按钮
///  https://api.flutter-io.cn/flutter/material/OutlinedButton-class.html
///
///  ElevatedButton 带阴影效果的按钮
///  https://api.flutter-io.cn/flutter/material/ElevatedButton-class.html
///
///
///  CupertinoButton  ios风格按钮
///  https://api.flutter-io.cn/flutter/cupertino/CupertinoButton-class.html
///
///
///
class ButtonPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("按钮组件"),
      ),
      body: Center(
        child: ListView(
          children: [
            // 基础按钮 https://api.flutter-io.cn/flutter/material/TextButton-class.html
              TextButton(
                //显示文本内容
                  child: Text(
                    "基础按钮",
                  ),
                  style: ButtonStyle(
                    foregroundColor: MaterialStateProperty.all(Colors.red) ,
                    textStyle: MaterialStateProperty.all(TextStyle(fontSize: 24),
                    )
                  ),
                  //点击事件
                  onPressed: () {
                    developer.log("基础按钮点击一次了");
                  },
                  // 长按事件
                  onLongPress: () {
                    developer.log("基础按钮长按一次了");
                  }) ,
            TextButton(child: Text(
              "基础按钮",
            ),
                style: ButtonStyle(
                  foregroundColor: MaterialStateProperty.resolveWith((states) =>  states.contains(MaterialState.pressed)? Colors.blue:Colors.red)
                ), onPressed: () {  },
            ),
            
            TextButton.icon(
                icon: Icon(Icons.add),
                label: Text("添加"),
                onPressed: () {
                  developer.log("基础按钮点击一次了");
                },
                // 长按事件
                onLongPress: () {
                  developer.log("基础按钮长按一次了");
                }),


            Padding(
                padding: EdgeInsets.all(8.0),
                child: OutlinedButton(
                  child: Text(
                    "基础按钮",
                    style: TextStyle(color: Colors.red),
                  ),
                  //点击事件
                  onPressed: () {
                    developer.log("基础按钮点击一次了");
                  },
                  // 长按事件
                  onLongPress: () {
                    developer.log("基础按钮长按一次了");
                  },
                  //风格自定义
                  style: OutlinedButton.styleFrom(
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(18.0)),
                      side: BorderSide(width: 2.0, color: Colors.yellow)),
                )),
            Padding(
              padding: EdgeInsets.all(8.0),
              child: ElevatedButton(
                  child: Text(
                    "基础按钮",
                    style: TextStyle(color: Colors.white),
                  ),
                  //点击事件
                  onPressed: () {
                    developer.log("基础按钮点击一次了");
                  },
                  // 长按事件
                  onLongPress: () {
                    developer.log("基础按钮长按一次了");
                  },
                  style: ElevatedButton.styleFrom(
                      side: BorderSide(color: Colors.white12),
                      shadowColor: Colors.green,
                      backgroundColor: Colors.greenAccent)),
            ),
            Padding(padding: EdgeInsets.all(8.0),
              child:  CupertinoButton.filled(
                child: Text("ios风格按钮"),
                onPressed: (){
                  developer.log("基础按钮点击一次了");
                },

              ),
            ),
            Padding(padding: EdgeInsets.all(8),
              child: FilledButton(
                child: Text("点击"),
                onPressed: (){},
              ),
            ) ,
            Padding(padding: EdgeInsets.all(8),
              child: FilledButton.tonal(
                child: Text("点击"),
                onPressed: (){},
              ),
            ) ,
          ],
        ),
      ),
      //悬浮按钮
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.phone),
        backgroundColor: Colors.lightGreen,
        onPressed: () {},
      ),
    );
  }
}
